<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AES加密</title>
</head>
<body>
<p id="p1"></p>
<br/>
<p id="p2"></p>
<p id="p3"></p>
<br/>
<p id="p4"></p>
<p id="p5"></p>
<script src="js/lib/aes.js"></script>
<script src="js/lib/mode-ecb.js"></script>
<script type="text/javascript">
    var keyCon="cad7abdb1a070422";

    function Encrypt(word){
        var key = CryptoJS.enc.Utf8.parse(keyCon);

        var srcs = CryptoJS.enc.Utf8.parse(word);
        var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
        return encrypted.toString();
    }

    function Decrypt(word){

        var key = CryptoJS.enc.Utf8.parse(keyCon);

        var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
        return CryptoJS.enc.Utf8.stringify(decrypt).toString();

    }

    var str='{"userName":"15099902355","passWord":"123456"}';
    var mmstr='n3JKBYM48AExJGLvGm9a7LTwKCfWrwexwKfXFnO2uZY=';

    var mm = Encrypt(str);
    var jm = Decrypt(mmstr);
    document.getElementById('p1').innerHTML='key：'+keyCon;

    document.getElementById('p2').innerHTML='加密前：'+str;
    document.getElementById('p3').innerHTML='加密后：'+mm;

    document.getElementById('p4').innerHTML='解密前：'+mmstr;
    document.getElementById('p5').innerHTML='解密后：'+jm;

</script>
</body>
</html>